import { request } from '@/api/request';
import { HttpMethod } from '@/services/types';

/**
 * PATCH /orders/post/:id 订单发货
 * @param id
 * @param params
 * @param options
 */
export async function resOrdersPost(
  id: number,
  params: API.OrdersPostParams,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/orders/post/' + id, {
    method: HttpMethod.PATCH,
    data: params,
    ...(options || {}),
  });
}

/**
 * PATCH /orders/comment/:id 评论订单
 * @param id
 * @param params
 * @param options
 */
export async function resOrdersComment(
  id: number,
  params: API.OrdersCommentParams,
  options?: { [key: string]: any }
) {
  return request<API.CommentStruct>('/orders/comment/' + id, {
    method: HttpMethod.PATCH,
    data: params,
    ...(options || {}),
  });
}

/**
 * GET /orders/express/:id 获取物流信息
 * @param id
 * @param options
 */
export async function resOrdersExpress(
  id: number,
  options?: { [key: string]: any }
) {
  return request<API.ExpressResult>('/orders/express/' + id, {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * GET /orders/detail/:id 订单详情
 * @param id
 * @param options
 */
export async function resOrdersDetail(
  id: number,
  options?: { [key: string]: any }
) {
  return request<API.OrdersDetailResult>('/orders/detail/' + id, {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * POST /orders/cancel/:id 取消订单
 * @param id
 * @param options
 */
export async function resOrdersCancel(
  id: number,
  options?: { [key: string]: any }
) {
  return request<API.OrdersDetailResult>('/orders/cancel/' + id, {
    method: HttpMethod.PATCH,
    ...(options || {}),
  });
}

/**
 * POST /orders/confirm/:id 确认收货
 * @param id
 * @param options
 */
export async function resOrdersConfirm(
  id: number,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/orders/confirm/' + id, {
    method: HttpMethod.POST,
    ...(options || {}),
  });
}

/**
 * POST /orders 提交订单
 * @param params
 * @param options
 */
export async function resAddOrders(
  params: API.AddOrdersParams,
  options?: { [key: string]: any }
) {
  return request<API.AddOrdersResult>('/orders', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * DELETE /orders 提交订单
 * @param id
 * @param options
 */
export async function resDeleteOrders(
  id: number,
  options?: { [key: string]: any }
) {
  return request<null>('/orders/' + id, {
    method: HttpMethod.DELETE,
    ...(options || {}),
  });
}

/**
 * GET /orders/preview 订单预览
 * @param options
 */
export async function resOrdersPreview(options?: { [key: string]: any }) {
  return request<API.OrdersPreview>('/orders/preview', {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * GET /orders 我的订单
 * @param params
 * @param options
 */
export async function resOrders(
  params: API.QueryOrders,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<API.OrdersStruct>>('/orders', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}

/**
 * GET /orders/receive 收到的订单
 * @param params
 * @param options
 */
export async function resOrdersReceive(
  params: API.QueryOrders,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<API.OrdersStruct>>('/orders/receive', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}

/*        admin       */

/**
 * GET /admin/orders 所有订单
 * @param params
 * @param options
 */
export async function resOrdersAdmin(
  params: API.QueryOrdersAdmin,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<API.OrdersStruct>>('/admin/orders', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}
